home *** CD-ROM | disk | FTP | other *** search
/ 10,000 Great Games / 10,000 Great Games.iso / Product / 66 / data1.cab / Source_Files / Src / Blaster.cpp < prev    next >
C/C++ Source or Header  |  2000-01-16  |  3KB  |  173 lines

  1. #include "stdafx.h"
  2. #include "resource.h"
  3.  
  4. CBlasterApp theApp;
  5.  
  6. class CAboutDlg : public CDialog
  7. {
  8. public:
  9.     CAboutDlg();
  10.  
  11.     //{{AFX_DATA(CAboutDlg)
  12.     enum { IDD = IDD_ABOUTBOX };
  13.     //}}AFX_DATA
  14.  
  15.     //{{AFX_VIRTUAL(CAboutDlg)
  16.     protected:
  17.     virtual void DoDataExchange(CDataExchange* pDX);
  18.     //}}AFX_VIRTUAL
  19.  
  20. protected:
  21.     //{{AFX_MSG(CAboutDlg)    
  22.     //}}AFX_MSG
  23.     DECLARE_MESSAGE_MAP()
  24. };
  25.  
  26. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  27.     //{{AFX_MSG_MAP(CAboutDlg)
  28.     //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30.  
  31. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  32. {
  33.     //{{AFX_DATA_INIT(CAboutDlg)
  34.     //}}AFX_DATA_INIT
  35. }
  36.  
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39.     CDialog::DoDataExchange(pDX);
  40.     //{{AFX_DATA_MAP(CAboutDlg)
  41.     //}}AFX_DATA_MAP
  42. }
  43.  
  44. BEGIN_MESSAGE_MAP(CBlasterApp, CWinApp)
  45.     //{{AFX_MSG_MAP(CBlasterApp)
  46.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  47.     //}}AFX_MSG_MAP
  48.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  49.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  50. END_MESSAGE_MAP()
  51.  
  52. CBlasterApp::CBlasterApp()
  53. {
  54. }
  55.  
  56. BOOL CBlasterApp::InitInstance()
  57. {    
  58.     // Display splash screen
  59.  
  60.     CDialog splash;
  61.     splash.Create(IDD_SPLASH_SCREEN);
  62.     splash.SetWindowPos(&CWnd::wndTop, 0, 0, 320, 240, SWP_NOMOVE);
  63.     splash.RedrawWindow();
  64.     
  65.     // Initialize windows app
  66.  
  67.     srand(time(0));
  68.     
  69.     Enable3dControls();
  70.     
  71.     SetRegistryKey(_T("3.14 Software"));
  72.     
  73.     LoadStdProfileSettings();
  74.  
  75.     read_profile();
  76.     
  77.     // Load game data
  78.  
  79.     init_directdraw_inawin();
  80.     init_directsound();
  81.     init_directinput();
  82.     init_fonts();
  83.     init_game_data();
  84.  
  85.     // Register the application's document templates.  Document templates
  86.     //  serve as the connection between documents, frame windows and views.
  87.  
  88.     CSingleDocTemplate* pDocTemplate;
  89.     pDocTemplate = new CSingleDocTemplate(
  90.         IDR_MAINFRAME,
  91.         RUNTIME_CLASS(CBlasterDoc),
  92.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  93.         RUNTIME_CLASS(CBlasterView));
  94.     AddDocTemplate(pDocTemplate);
  95.  
  96.     // Make .bdl belong to our application
  97.  
  98.     RegisterShellFileTypes();
  99.  
  100.     // Parse command line for standard shell commands, DDE, file open
  101.     
  102.     CCommandLineInfo cmdInfo;
  103.     ParseCommandLine(cmdInfo);
  104.  
  105.     // Dispatch commands specified on the command line
  106.     
  107.     if (!ProcessShellCommand(cmdInfo))
  108.         return FALSE;
  109.  
  110.     // Destroy splash screen
  111.  
  112.     splash.DestroyWindow();
  113.  
  114.     // The one and only window has been initialized, so show and update it.
  115.  
  116.     CMainFrame::ResizeToFitGameArea();
  117.     m_pMainWnd->ShowWindow(SW_SHOW);
  118.     m_pMainWnd->UpdateWindow();
  119.  
  120.     // Accept files
  121.  
  122.     m_pMainWnd->DragAcceptFiles();
  123.  
  124.     // Initialize things we need a window for
  125.  
  126.     init_directsound_primarybuffer();    
  127.     init_music();    
  128.     init_keyboard();
  129.     init_joystick();    
  130.  
  131.     // Quickstart
  132.  
  133.     mainwindow->PostMessage(WM_COMMAND, ID_QUICKSTART, 0);
  134.  
  135.     // Start message pump
  136.  
  137.     return TRUE;
  138. }
  139.  
  140. int CBlasterApp::ExitInstance() 
  141. {
  142.     // Kill game
  143.  
  144.     deinit_game();
  145.  
  146.     // Save state of the program
  147.  
  148.     write_profile();
  149.  
  150.     // Call base class
  151.  
  152.     return CWinApp::ExitInstance();
  153. }
  154.  
  155. void CBlasterApp::OnAppAbout()
  156. {
  157.     CAboutDlg aboutDlg;
  158.     aboutDlg.DoModal();
  159. }
  160.  
  161. void deinit_game()
  162. {    
  163.     deinit_game_loop();
  164.     deinit_keyboard();
  165.     deinit_joystick();
  166.     deinit_music();
  167.     deinit_game_data();
  168.     deinit_fonts();
  169.     deinit_directsound();    
  170.     deinit_directinput();
  171.     deinit_directdraw();
  172. }
  173.